<%@ page contentType="text/html; charset=EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*"%>
<%@ include file="db.jsp" %>

<%
	String realFolder = "C:\\Users\\jspPro";
	String encType = "euc-kr";

	int sizeLimit = 15 * 1024 * 1024;

	MultipartRequest multi = null;
	multi = new MultipartRequest(request, realFolder, sizeLimit, encType, new DefaultFileRenamePolicy());

	String fileName = multi.getFilesystemName("userFile");
	String originFileName = multi.getOriginalFileName("userFile");

	File file = multi.getFile("userFile");

	String name = multi.getParameter("name");
	String pass = multi.getParameter("pass");
	String email = multi.getParameter("email");
	String title = multi.getParameter("title");
	String contents = multi.getParameter("contents");

	String nullCheck = multi.getParameter("radioGroup");
	//System.out.print(nullCheck);
	String genre = null;
	if(nullCheck == null){
		nullCheck = "0";
	}else{
		//feel = Integer.parseInt(multi.getParameter("radioGroup")); 
		genre = multi.getParameter("radioGroup"); 
	}
	
	String nullCheck1 = multi.getParameter("feel");
	System.out.print(nullCheck1);
	int feel = 0;
	if(nullCheck1 == null){
		nullCheck = "0";
	}else{
		feel = Integer.parseInt(multi.getParameter("feel")); 
	}
	
	Statement stmt = conn.createStatement();

	Calendar dateIn = Calendar.getInstance();
	String indate = Integer.toString(dateIn.get(Calendar.YEAR)) + "-";
	indate = indate + Integer.toString(dateIn.get(Calendar.MONTH)+1) + "-";
	indate = indate + Integer.toString(dateIn.get(Calendar.DATE)) + " ";
	indate = indate + Integer.toString(dateIn.get(Calendar.HOUR_OF_DAY)) + ":";
	indate = indate + Integer.toString(dateIn.get(Calendar.MINUTE)) + ":";
	indate = indate + Integer.toString(dateIn.get(Calendar.SECOND));

	String strSQL = "SELECT Max(num) FROM s_store";
	ResultSet rs = stmt.executeQuery(strSQL);
	int num = 1;

	if (!rs.wasNull())
	{
		rs.next();
		num = rs.getInt(1) + 1;
	}
	
	strSQL = "INSERT INTO s_store (num, name, pass, email, title, contents, writedate, readcount, filename)";
	strSQL = strSQL + "VALUES('" + num + "', '" + name + "', '" + pass + "', '" + email + "',";
	strSQL = strSQL + "'" + title + "', '" + contents + "', '" + indate + "', ' 0 ', '" + fileName + "')";
	stmt.executeUpdate(strSQL);
	
	String strSQL1 = "SELECT Max(num) FROM music";
    ResultSet rs1 = stmt.executeQuery(strSQL1);
    if (!rs1.wasNull())
	{
		rs1.next();
		num = rs1.getInt(1) + 1;
	}
    strSQL1 = "INSERT INTO s_store (num, fileName, genre, feel, 0)";
    strSQL1 = strSQL + "VALUES('"+num+"','"+fileName+"','"+genre+"','"+feel+"','0')";
    stmt.executeUpdate(strSQL1);
    
	stmt.close();
	conn.close();

	response.sendRedirect("store.jsp");
%>